package com.ruoyi.logistic.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.logistic.domain.NetworkSheetPriceContract;
import com.ruoyi.logistic.domain.NetworkSheetPriceContractRecord;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.vo.NetworkSheetPriceContractVo;
import com.ruoyi.logistic.mapper.NetworkSheetPriceContractMapper;
import com.ruoyi.logistic.mapper.NetworkSheetPriceContractRecordMapper;
import com.ruoyi.logistic.service.NetworkSheetPriceContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;
@Service
public class NetworkSheetPriceContractServiceImpl implements NetworkSheetPriceContractService {
    @Autowired
    private NetworkSheetPriceContractMapper networkSheetPriceContractMapper;
    @Autowired
    private NetworkSheetPriceContractRecordMapper networkSheetPriceContractRecordMapper;
    @Override
    public List<NetworkSheetPriceContract> selectAll(PageDate pageDate) {
        PageHelper.startPage(pageDate);
        return networkSheetPriceContractMapper.selectAll();
    }

    @Override
    public Boolean insert(NetworkSheetPriceContract networkSheetPriceContract) {
        return networkSheetPriceContractMapper.insert(networkSheetPriceContract);
    }

    @Override
    public Boolean update(NetworkSheetPriceContract networkSheetPriceContract) {
        NetworkSheetPriceContractRecord record = new NetworkSheetPriceContractRecord();
        record.setContent(networkSheetPriceContract.getSheetFee()+"");
        record.setContractId(networkSheetPriceContract.getId());
        record.setUpdateBy(SecurityUtils.getUserId());
        networkSheetPriceContractRecordMapper.insert(record);
        return networkSheetPriceContractMapper.update(networkSheetPriceContract);
    }

    @Override
    public Boolean deleteById(Integer id) {
        return networkSheetPriceContractMapper.deleteById(id);
    }

    @Override
    public NetworkSheetPriceContract findById(Integer id) {
        return networkSheetPriceContractMapper.findById(id);
    }

    @Override
    public List<NetworkSheetPriceContract> search(NetworkSheetPriceContractVo networkSheetPriceContractVo) {
        PageHelper.startPage(networkSheetPriceContractVo.getPageDate());
        return networkSheetPriceContractMapper.search(networkSheetPriceContractVo);
    }


    @Override
    public List<NetworkSheetPriceContractRecord> searchDetail(Date startTime, Date endTime, Integer id) {

        return networkSheetPriceContractRecordMapper.search(startTime,endTime,id);
    }
}
